import  json  #json数据格式是字符串
#用于不同语言之间的数据传输
#dumps把列表或者字典转化成字符串
#loads把字符串转化成列表或者字典

#准备列表，列表里的每一个元素都是字典，将其转化成json
data= [{"name":"张大山","age":11}, {"name":"张大大","age":11}, {"name":"张大爷","age":11}]
print(type(data))
json_str=json.dumps(data,ensure_ascii=False)
print(type(json_str))
print(json_str)


#准备字典转化为json
d={"name":"张大山","age":11}
json_str1=json.dumps(d,ensure_ascii=False)
print(json_str1)

#将jSON字符串转化为列表
c='[{"name":"张大山","age":11}, {"name":"张大大","age":11}, {"name":"张大爷","age":11}]'
json1=json.loads(c)
print(type(json1))
print(json1)

#将json字符串转化为字典
a='{"name":"张大山","age":11}'
json2=json.loads(a)
print(type(json2))
print(json2)